﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FlashCards.Models;
using FlashCards.WebApplication.DAL;
using FlashCards.WebApplication.Controls;

namespace FlashCards.WebApplication.Pages
{
    public partial class Friends : System.Web.UI.Page
    {
        private User _user;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (_user == null)
            {
                if(Session["LoggedUser"] != null)
                    _user = Session["LoggedUser"] as User;

                foreach (string login in _user.Friends)
                {
                    // chyba lepiej byłoby odpytać raz bazę danych o wszystkich znajomych, niż każdorazowo o jedną krotkę
                    User friend = DataBaseConnector.GetUserByName(login);
                    FriendControl ctrl = this.LoadControl("../Controls/FriendControl.ascx") as FriendControl;
                    ctrl.User = friend;
                    FriendsPanel.Controls.Add(ctrl);
                }
            }
        }
    }
}